<?php

/**
 * music actions.
 *
 * @package    musica
 * @subpackage music
 * @author     Rafael de Mello
 */
class musicActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $c = new Criteria();
    $c->addAscendingOrderByColumn(ArtistPeer::SLUG);
    $this->artists = ArtistPeer::doSelect($c);
  }

  public function executeArtist(sfWebRequest $request)
  {
    $c = new Criteria();
    $c->add(ArtistPeer::SLUG, $request->getParameter('artist'));
    $this->artist = ArtistPeer::doSelectOne($c);

    $this->forward404Unless($this->artist);
  }

  public function executeExtras(sfWebRequest $request)
  {
    $action = 'artist' . ucfirst(substr($request->getParameter('extra'), 1));
    $this->forward('music', $action);
    return $this->renderText($action);
  }

  public function executeArtistBio()
  {
  }

  public function executeArtistPictures()
  {
  }

  public function executeArtistVideos()
  {
  }

  public function executeArtistAlbums()
  {
  }

  public function executeArtistTracks()
  {
  }

  public function executeArtistEvents()
  {
  }

  public function executeArtistNews()
  {
  }

  public function executeArtistSimilars()
  {
  }

  public function executeArtistTags()
  {
  }



  public function executeAlbum(sfWebRequest $request)
  {
    $c = new Criteria();
    $c->add(ArtistPeer::SLUG, $request->getParameter('artist'));
    $this->artist = ArtistPeer::doSelectOne($c);

    $this->forward404Unless($this->artist);

    $c = new Criteria();
    $c->add(AlbumPeer::SLUG, $request->getParameter('album'));
    $c->add(AlbumPeer::ARTIST_ID, $this->artist->getId());

    $this->album = AlbumPeer::doSelectOne($c);

    $this->forward404Unless($this->album);

    $c = new Criteria();
    $c->addAscendingOrderByColumn(AlbumTrackPeer::TRACK_NUMBER);
    $this->tracks = $this->album->getAlbumTracks($c);
  }

  public function executeMusic(sfWebRequest $request)
  {

    $c = new Criteria();
    $c->add(ArtistPeer::SLUG, $request->getParameter('artist'));
    $this->artist = ArtistPeer::doSelectOne($c);

    $this->forward404Unless($this->artist);

    $c = new Criteria();
    $c->add(AlbumPeer::SLUG, $request->getParameter('album'));
    $c->add(AlbumPeer::ARTIST_ID, $this->artist->getId());

    $this->album = AlbumPeer::doSelectOne($c);

    $this->forward404Unless($this->album);

    $c = new Criteria();
    //$c->addJoin(MusicPeer::ID, AlbumTrackPeer::MUSIC_ID, Criteria::INNER_JOIN);
    $c->add(AlbumTrackPeer::ALBUM_ID, $this->album->getId());
    $c->add(MusicPeer::ARTIST_ID, $this->artist->getId());
    $c->add(MusicPeer::SLUG, $request->getParameter('music'));
    $c->setLimit(1);

    $music = AlbumTrackPeer::doSelectJoinMusic($c);
    $this->music = isset($music[0]) ? $music[0] : false;

    $this->forward404Unless($this->music);

    $c = new Criteria();
    $c->addAscendingOrderByColumn(AlbumTrackPeer::TRACK_NUMBER);
    $this->tracks = $this->album->getAlbumTracks($c);
  }

}
